package com.atguigu.gmall.file;

import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ClassUtils;

/**
 * @Author: 李旭
 * @Time: 15:02
 * @Description:
 */
public class FileUploadDemo {
    public static void main(String[] args) throws Exception{
        //0:初始化配置文件   流只能读取绝对路径  不认识相对路径
        String path = ClassUtils.getDefaultClassLoader().
                getResource("fdfs_client.conf").getPath();
        ClientGlobal.init(path);
        //1:连接 Tracker跟踪器
        TrackerClient trackerClient = new TrackerClient();
        //TrackerServer  存储节点的IP及端口号
        TrackerServer trackerServer = trackerClient.getConnection();
        //2:连接存储节点
        StorageClient1 storageClient1 = new StorageClient1(trackerServer,null);
        //3:上传文件
        String fileId = storageClient1.upload_file1(
                "D:\\尚品汇商城\\资料\\图片\\logo\\f74c5dc87e89fdd4.png",
                "jpg",
                null
        );
        // http://192.168.200.129:8080/group1/M00/00/00/wKjIgWBldImAc2k1AAHUNCqGgBA266.jpg
        System.out.println("http://192.168.200.129:8080/" + fileId);

        //storageClient1.d
    }
}
